import '../../../lib_basemodel/chat_room/chat/chat_content.dart';
import '../../../lib_basemodel/chat_room/chat/show_item.dart';
import '../../../lib_basemodel/chat_room/habibi-msg/hb_rtm_msg.dart';
import '../input/item_style.dart';

class RoomMsg {
  // final Message msg;

  final ChatContent? chatContent;
  final HbRtmMsg? rtmMsg;

  // late MessageData msgData;
  // late Scene scene;
  // User? sender;

  /// 引用消息
  // Message? quoteMsg;

  // RoomMsg(this.msg, this.content) {

  //   msg.data.content.unpackInto(content);

  //   if (content is ChatContent) {
  //     sender = (content as ChatContent).sender;
  //     if ((content as ChatContent).hasQuoteMsg()) {
  //       quoteMsg = (content as ChatContent).quoteMsg;
  //     }
  //   } else if (content is CardChatContent) {
  //     sender = (content as CardChatContent).sender;
  //     if ((content as CardChatContent).hasQuoteMsg()) {
  //       quoteMsg = (content as CardChatContent).quoteMsg;
  //     }
  //   }
  // }

  RoomMsg({
    this.chatContent,
    this.rtmMsg,
  });

  // RoomMsg(this.msg, this.content) {
  //   msgData = msg.data ?? MessageData();
  //   if (content is ChatContent) {
  //     ChatContent chatContent = content;
  //     msgData.content =
  //         chatContent.showItem?.map((e) => e?.text ?? '').join('') ?? '';
  //     sender = chatContent.sender;
  //     quoteMsg = chatContent.quoteMsg;
  //   } else {
  //     msgData.content = content.toString();
  //   }
  // }

  // void clearQuoteMsg() {
  //   // if (content is ChatContent) {
  //   //   (content as ChatContent).clearQuoteMsg();
  //   // } else if (content is CardChatContent) {
  //   //   (content as CardChatContent).clearQuoteMsg();
  //   // }
  // }

  void clearQuoteMsg() {
    // if (content is ChatContent) {
    //   (content as ChatContent).quoteMsg = null;
    // }
  }

  // bool get hasQuoteMsg => quoteMsg != null;
}

extension ChatMsgExtension on RoomMsg {
  // List<ShowItem?>? get contentItems =>
  //     content is ChatContent ? (content as ChatContent).showItem : [];

  // CardChatContent? get cardContent => content is CardChatContent ? (content as CardChatContent) : null;

  String get quoteShowMsg {
    String msg = '';
    // if (content is ChatContent && quoteMsg != null) {
    //   // List<String?> quoteTexts =
    //   //     quoteMsg?.data?.contentItems?.map((e) => e?.text) ?? [];

    //   List<String?> quoteTexts = ['a', 'b'];
    //   msg = quoteTexts.join('');
    // }
    // return '${sender?.nickname ?? '[User]'}: $msg';
    return msg;
  }
}

extension ShowItemExtension on ShowItem {
  String? get desc {
    switch (style) {
      case ItemStyle.text:
        return text ?? '';
      case ItemStyle.icon:
        return ' [Icon] ';
      case ItemStyle.link:
        return (text?.isEmpty ?? false) ? ' [Link] ' : text;
      case ItemStyle.emote:
        return (text?.isEmpty ?? false) ? ' [Emote] ' : text;
      default:
        return text;
    }
  }
}
